/*
 * Tri.java
 *
 * Created on 13 luty 2008, 11:47
 *
 * Klasa reprezentuje JEDEN trojkat !!!
 */
  
package trojkaty;

import java.awt.Color;
import javax.vecmath.Point3d;
import javax.vecmath.Vector3d;

/**
 * Klasa opisujaca trojkat
 * @author arkadiusz
 */

public class Tri {
   Vector3d vab;
   Vector3d vbc;
   Vector3d vca;
   Point3d a;
   Point3d b;
   Point3d c;
   
   public Tri() {
   }
   public Tri(Point3d a, Point3d b, Point3d c) {
      this.a = a;
      this.b = b;
      this.c = c;
      this.vab = new Vector3d(a.x - b.x, a.y - b.y, a.z - b.z);
      this.vbc = new Vector3d(b.x - c.x, b.y - c.y, b.z - c.z);
      /// ???? this.vca = new Vector3d(c.x - a.x, c.y - a.x, c.z - a.z);
this.vca = new Vector3d(c.x - a.x, c.y - a.y, c.z - a.z);
   }
   
   public Point3d[] getPoints3d(){
      return new Point3d[]{this.a, this.b, this.c};
   }
   public Vector3d getNormalny(){
      Vector3d vr = new Vector3d();
      vr.cross(this.vab , this.vbc);
      return vr;
   }
   public Color getColor(){
     Vector3d v = this.getNormalny();
     v.normalize();
    
     int r = (int)(255*Math.abs(v.x));
     int g = (int)(255*Math.abs(v.y));
     int b = (int)(255*Math.abs(v.z));
     
     //---
     //Biorę kolor domiunujacy
     if (r>g && r>b) { r=255; g=0; b=0;}
     else if (g>r && g>b) { r=0; g=255; b=0;}
     else if (b>r && b>g) { r=0; g=0; b=255;}
     else if (g==r && g>b) { r=255; g=255; b=0;}
     else if (b==r && b>g) { r=255; g=0; b=255;}
     else if (g==b && g>r) { r=0; g=255; b=255;}
     //===
     
     //System.out.println(r+","+g+","+b);
     return new Color(r,g,b);
   }
   public Point3d getSirodek(){
     return new Point3d( 
             (this.a.x + this.b.x + this.c.x)/3.0,
             (this.a.y + this.b.y + this.c.y)/3.0,
             (this.a.z + this.b.z + this.c.z)/3.0
             );
   }
}
